home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / gtlayout-source.lha / LTP_MakeItem.c < prev    next >
C/C++ Source or Header  |  1996-03-18  |  3KB  |  127 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. #ifdef DO_MENUS
  15.  
  16.     /* LTP_MakeItem(RootMenu *Root,struct NewMenu *Template):
  17.      *
  18.      *    Create a single menu item and fill it in.
  19.      */
  20.  
  21. ItemNode *
  22. LTP_MakeItem(RootMenu *Root,struct NewMenu *Template)
  23. {
  24.     ItemNode    *Item;
  25.     LONG         Size;
  26.  
  27.         // Which type of entry to create
  28.  
  29.     if(Template->nm_Label == NM_BARLABEL)
  30.         Size = sizeof(ItemNode) + sizeof(struct Image);
  31.     else
  32.         Size = sizeof(ItemNode) + sizeof(struct IntuiText);
  33.  
  34.         // Make room for it
  35.  
  36.     if(Item = AsmAllocPooled(Root->Pool,Size,SysBase))
  37.     {
  38.             // Is it a separator bar?
  39.  
  40.         if(Template->nm_Label == NM_BARLABEL)
  41.         {
  42.             struct Image *Image = (struct Image *)(Item + 1);
  43.  
  44.                 // Fill in the image data
  45.  
  46.             Image->LeftEdge        = 2;
  47.             Image->TopEdge        = 2;
  48.             Image->Depth        = Root->DrawInfo->dri_Depth;
  49.             Image->PlaneOnOff    = Root->TextPen;
  50.             Image->Height        = 2;
  51.  
  52.                 // Now take care of the item itself
  53.  
  54.             Item->Item.ItemFill = Image;
  55.             Item->Item.Width    = 2;
  56.             Item->Item.Height    = 2 + Image->Height + 2;
  57.             Item->Flags            = ITEMF_IsBar;
  58.             Item->Item.Flags    = HIGHNONE;
  59.         }
  60.         else
  61.         {
  62.             struct IntuiText *IntuiText = (struct IntuiText *)(Item + 1);
  63.  
  64.                 // Fill in the label
  65.  
  66.             LTP_InitIText(Root,IntuiText);
  67.  
  68.             IntuiText->LeftEdge    = 2;
  69.             IntuiText->TopEdge    = (Root->ItemHeight - Root->RPort.TxHeight) / 2;
  70.             IntuiText->IText    = Template->nm_Label;
  71.  
  72.                 // Now take care of the item itself
  73.  
  74.             Item->Item.ItemFill    = IntuiText;
  75.             Item->Item.Width    = 2 + TextLength(&Root->RPort,IntuiText->IText,strlen(IntuiText->IText)) + 2;
  76.             Item->Item.Height    = Root->ItemHeight;
  77.             Item->Item.Flags    = ITEMTEXT | HIGHCOMP;
  78.  
  79.                 // Is there a command to take care of?
  80.  
  81.             if(Template->nm_CommKey)
  82.             {
  83.                     // Special command?
  84.  
  85.                 if(Template->nm_Flags & NM_COMMANDSTRING)
  86.                 {
  87.                     Item->ExtraLabel    = Template->nm_CommKey;
  88.                     Item->Flags            = ITEMF_Command;
  89.                 }
  90.                 else
  91.                 {
  92.                     DB(kprintf("commkey 0x%08lx\n",Template->nm_CommKey));
  93.  
  94.                         // Just put in the usual command sequence in there
  95.  
  96.                     Item->Item.Flags    |= COMMSEQ;
  97.                     Item->Item.Command     = (BYTE)ToUpper(Template->nm_CommKey[0]);
  98.                 }
  99.             }
  100.  
  101.                 // Move up for the checkmark
  102.  
  103.             if(Template->nm_Flags & CHECKIT)
  104.                 Item->Item.Width += 2 + Root->CheckWidth;
  105.  
  106.                 // Disable the item if necessary
  107.  
  108.             if(!(Template->nm_Flags & NM_ITEMDISABLED))
  109.                 Item->Item.Flags |= ITEMENABLED;
  110.  
  111.                 // Fill in the rest of the flags
  112.  
  113.             Item->Item.Flags |= Template->nm_Flags & (CHECKIT | MENUTOGGLE | CHECKED);
  114.  
  115.                 // Take care of the remaining data
  116.  
  117.             Item->Item.MutualExclude = Template->nm_MutualExclude;
  118.         }
  119.  
  120.         Item->UserData = Template->nm_UserData;
  121.     }
  122.  
  123.     return(Item);
  124. }
  125.  
  126. #endif    /* DO_MENUS */
  127.